package com.czy.owner.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.czy.owner.R;
import com.czy.owner.entity.OrdersListModel;
import com.czy.owner.utils.glide.GlideUtils;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;


/**
 * Created by wangyang on 2017/4/20 0020.
 */
public class OrderSubAdapter extends RecyclerArrayAdapter<OrdersListModel.ListBean.OrderItemsBean> {
    private Context context;

    public OrderSubAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new com.czy.owner.adapter.OrderSubAdapter.OrderSubViewHolder(parent);

    }

    class OrderSubViewHolder extends BaseViewHolder<OrdersListModel.ListBean.OrderItemsBean> {
        private ImageView imgProduct;
        private TextView tvProductDescription;
        private TextView tvProductPrice;
        private TextView tvProductCount;
        private TextView tvSpac;
        private TextView tvMemberPrice;//会员价

        public OrderSubViewHolder(ViewGroup parent) {
            super(parent, R.layout.item_order_sub);
            imgProduct = $(R.id.img_product);
            tvProductDescription = $(R.id.tv_product_description);
            tvProductPrice = $(R.id.tv_product_price);
            tvProductCount = $(R.id.tv_product_count);
            tvSpac = $(R.id.tv_spac);
            tvMemberPrice = $(R.id.tv_member_price);

        }

        @Override
        public void setData(OrdersListModel.ListBean.OrderItemsBean data) {
            double originalPrice = data.getOriginalPrice();//原价
            double price = data.getPrice();//会员价
            if (originalPrice > price) {
                tvMemberPrice.setVisibility(View.VISIBLE);
                tvMemberPrice.setText("￥"+String.format("%.2f", price));
            } else {
                tvMemberPrice.setVisibility(View.GONE);
            }
            tvProductDescription.setText(data.getItemName());
            tvProductPrice.setText("￥" + String.format("%.2f", price));
            tvProductCount.setText("x" + data.getCount());
            if (TextUtils.isEmpty(data.getSpecValue())) {
                tvSpac.setVisibility(View.GONE);
            } else {
                if (data.getSpecValue().contains("规格:无规格")) {
                    tvSpac.setVisibility(View.GONE);
                } else {
                    tvSpac.setVisibility(View.VISIBLE);
                    tvSpac.setText(data.getSpecValue());
                }

            }
            GlideUtils.loadImage(context, data.getLogo(), imgProduct, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                @Override
                public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {

                }

                @Override
                public void onLoadingError(String source, Exception e) {

                }
            }, R.mipmap.default_icon, R.mipmap.default_icon);

        }

    }
}
